#include "blockqe.hpp"

//实现两个线程，producer和consumer
void* producer(void* arg){
    BlockQueue<int> * bq = (BlockQueue<int>*)arg;
    while(true){
        int data = rand() % 100 + 1;
        bq->Push(data);
        std::cout<<"Producer: "<<data<<std::endl;
    }
    
}
void* consumer(void* arg){
    BlockQueue<int> * bq = (BlockQueue<int>*)arg;
    while(true){
        sleep(1);
        int data = 0;
        bq->Pop(data);
        std::cout<<"consumer: "<<data<<std::endl;
    }
    
}

int main(){
    srand((unsigned int)time(nullptr));
    pthread_t pd,cs;
    BlockQueue<int>* bq = new BlockQueue<int>;
    //创建线程
    pthread_create(&pd,nullptr,producer,bq);
    pthread_create(&cs,nullptr,consumer,bq);
    //等待线程
    pthread_join(pd,nullptr);
    pthread_join(cs,nullptr);
    delete bq;
    return 0;
}